package com.sky.controller.admin;


import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/order")
public class OrderController {

    @Autowired
    private OrdersService ordersService;

    @GetMapping("/conditionSearch")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO dto) {
        PageResult pageResult = ordersService.conditionSearch(dto);
        return Result.success(pageResult);
    }

    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable("id") Long id) {
        ordersService.delivery(id);
        return Result.success();
    }
    @PutMapping("/confirm")
    public Result confirm(@RequestBody OrdersConfirmDTO dto) {
        ordersService.confirm(dto.getId());
        return Result.success();
    }

    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO dto) {
        ordersService.rejection(dto);
        return Result.success();
    }

    @GetMapping("details/{id}")
    public Result<OrderVO> details(@PathVariable Long id) {
        OrderVO orderVO = ordersService.orderDetail(id);
        return Result.success(orderVO);
    }
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics(){
        OrderStatisticsVO orderStatisticsVO= ordersService.statistics();
        return Result.success(orderStatisticsVO);
    }

    /**
     * 取消订单
     * @param
     * @return
     */
    @PutMapping("/cancel")
    public Result cancelOrders(@RequestBody OrdersCancelDTO ordersCancelDTO){
        ordersService.cancelOrders(ordersCancelDTO);
        return Result.success();
    }

    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable Long id){
        ordersService.completeOrders(id);
        return Result.success();
    }
}
